Restore the generated tests module created by `cargo new`
authorCarol (Nichols || Goulding) <carol.nichols@gmail.com>
Sat, 4 Mar 2017 20:51:09 +0000 (15:51 -0500)
committerCarol (Nichols || Goulding) <carol.nichols@gmail.com>
Sat, 4 Mar 2017 20:51:09 +0000 (15:51 -0500)
Appears to have been removed unintentionally in #3004.

src/cargo/ops/cargo_new.rs
tests/new.rs

index 4905a14857c56a5ca52f0d00ad1a9262d8802a42..6f77801ff5eefc5d518f69f5a8ca9e9e44a19625 100644 (file)
@@ -582,7 +582,7 @@ fn collect_template_dir(template_path: &PathBuf, _: &Path) -> CargoResult<Vec<Bo
                                       human(format!("entry is somehow not a subpath \
                                                      of the directory being walked."))
                                   })));
-        templates.push(Box::new(InputFileTemplateFile::new(entry_path, 
+        templates.push(Box::new(InputFileTemplateFile::new(entry_path,
                                                            dest_file_name.to_path_buf())));
         Ok(())
     }));
@@ -707,8 +707,11 @@ authors = [{{toml-escape author}}]
 /// Create a new "lib" project
 fn create_lib_template() -> Vec<Box<TemplateFile>> {
     let lib_file = Box::new(InMemoryTemplateFile::new(PathBuf::from("src/lib.rs"),
-    String::from(r#"#[test]
-fn it_works() {
+    String::from(r#"#[cfg(test)]
+mod tests {
+    #[test]
+    fn it_works() {
+    }
 }
 "#)));
     vec![lib_file]
index 2e9a770b09b770568cb3d13af3d34dfc9a175572..1e666a7a3e25ec17ada20b1a1838217077598720 100644 (file)
@@ -32,6 +32,17 @@ fn simple_lib() {
     assert_that(&paths::root().join("foo/src/lib.rs"), existing_file());
     assert_that(&paths::root().join("foo/.gitignore"), is_not(existing_file()));
 
+    let lib = paths::root().join("foo/src/lib.rs");
+    let mut contents = String::new();
+    File::open(&lib).unwrap().read_to_string(&mut contents).unwrap();
+    assert_eq!(contents, r#"#[cfg(test)]
+mod tests {
+    #[test]
+    fn it_works() {
+    }
+}
+"#);
+
     assert_that(cargo_process("build").cwd(&paths::root().join("foo")),
                 execs().with_status(0));
 }